/*
 * 诚信记分查询
 * @author EX-XIEYUWEN001
 * Filename:    WarningDeductionController.java
 * Copyright:   2014 中国平安保险（集团）股份有限公司 版权所有
 * Company:     平安科技养老险及健康险系统开发部
 * Create at:   2014年11月19日
 */
package com.paic.mhis.hcpms.warning.web.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.paic.mhis.core.auth.biz.service.UserDetails;
import com.paic.mhis.hcpms.trust.biz.service.IntegrityMedicalService;
import com.paic.mhis.hcpms.trust.web.vo.PointCutVO;
import com.paic.mhis.hcpms.warning.biz.service.WarningDeductionService;
import com.paic.mhis.hcpms.warning.web.vo.WarningDeductionVO;
import com.paic.pafa.app.biz.service.BusinessServiceException;
import com.paic.pafa.appclient.annotation.BizServicesProxy;
import com.paic.pafa.exceptions.BusinessException;

@Controller
@RequestMapping("/warningDeduction/")
public class WarningDeductionController {
	@BizServicesProxy(beanName = "warningDeductionService")
	private WarningDeductionService warningDeductionService;

	@BizServicesProxy(beanName = "integrityMedicalService")
	private IntegrityMedicalService integrityMedicalService;

	/**
	 * 评分标准信息
	 * @param search
	 * @param request
	 * @return
	 * @throws BusinessServiceException
	 * @throws BusinessException
	 */
	@RequestMapping("warningDeduction.do")
	@ResponseBody
	public Map<String, Object> warningDeduction(@ModelAttribute WarningDeductionVO search, HttpServletRequest request)
			throws BusinessServiceException, BusinessException {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("scoreLevel", search.getScoreLevel());
		paramMap.put("scoreType", search.getScoreType());
		paramMap.put("parentId", StringUtils.isEmpty(search.getParentId()) ? null : search.getParentId());
		paramMap.put("idStandardscore", StringUtils.isEmpty(search.getIdStandardscore()) ? null : search.getIdStandardscore());
		Map<String, Object> map = new HashMap<String, Object>();
		if (StringUtils.isNotBlank(search.getScoreLevel()) && StringUtils.isNotBlank(search.getScoreType())) {
			map.put("warningDeductions", warningDeductionService.findWarningDeduction(paramMap));
		} else {
			map.put("warningDeductions", null);
		}
		return map;
	}

	/**
	 * 临时扣分查询(有限制条件)
	 * @param search
	 * @param request
	 * @return
	 * @throws BusinessException
	 */
	@RequestMapping("findPointCutTemps.do")
	@ResponseBody
	public Map<String, Object> findPointCutTemps(@ModelAttribute PointCutVO search, HttpServletRequest request)
			throws BusinessException {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("caseType", StringUtils.isEmpty(search.getCaseType()) ? null : search.getCaseType());
		paramMap.put("caseNo", StringUtils.isEmpty(search.getCaseNo()) ? null : search.getCaseNo());
		paramMap.put("targetType", StringUtils.isEmpty(search.getTargetType()) ? null : search.getTargetType());
		paramMap.put("targetNo", StringUtils.isEmpty(search.getTargetNo()) ? null : search.getTargetNo());
		paramMap.put("orgCode", StringUtils.isEmpty(search.getOrgCode()) ? null : search.getOrgCode());
		Map<String, Object> map = new HashMap<String, Object>();
		boolean isTrue = StringUtils.isNotEmpty(search.getTargetNo());
		if (isTrue) {
			map.put("pointCutTemps", integrityMedicalService.findPointCutTemps(paramMap));
		} else {
			map.put("pointCutTemps", null);
		}
		return map;
	}
	
	/**
	 * 临时扣分查询
	 * @param search
	 * @param request
	 * @return
	 * @throws BusinessException
	 */
	@RequestMapping("findPointCutTempScose.do")
	@ResponseBody
	public Map<String, Object> findPointCutTempScose(@ModelAttribute PointCutVO search, HttpServletRequest request)
			throws BusinessException {
		UserDetails user = (UserDetails) request.getSession().getAttribute("user");
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("userName", user.getUsername());
		paramMap.put("caseType", StringUtils.isEmpty(search.getCaseType()) ? null : search.getCaseType());
		paramMap.put("caseNo", StringUtils.isEmpty(search.getCaseNo()) ? null : search.getCaseNo());
		paramMap.put("targetType", StringUtils.isEmpty(search.getTargetType()) ? null : search.getTargetType());
		paramMap.put("targetNo", StringUtils.isEmpty(search.getTargetNo()) ? null : search.getTargetNo());
		paramMap.put("orgCode", StringUtils.isEmpty(search.getOrgCode()) ? null : search.getOrgCode());
		Map<String, Object> map = new HashMap<String, Object>();
		if(StringUtils.isNotEmpty(search.getCaseType())
				&&StringUtils.isNotEmpty(search.getCaseNo())){
				map.put("pointCutTemps", integrityMedicalService.findPointCutStorageCollections(paramMap));
		}else{
			map.put("pointCutTemps", null);
		}
		return map;
	}

	/**
	 * 扣分查询
	 * @param search
	 * @param request
	 * @return
	 * @throws BusinessException
	 */
	@RequestMapping("findPointCuts.do")
	@ResponseBody
	public Map<String, Object> findPointCuts(@ModelAttribute PointCutVO search, HttpServletRequest request)
			throws BusinessException {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("caseType", StringUtils.isEmpty(search.getCaseType()) ? null : search.getCaseType());
		paramMap.put("caseNo", StringUtils.isEmpty(search.getCaseNo()) ? null : search.getCaseNo());
		paramMap.put("targetType", StringUtils.isEmpty(search.getTargetType()) ? null : search.getTargetType());
		paramMap.put("targetNo", StringUtils.isEmpty(search.getTargetNo()) ? null : search.getTargetNo());
		paramMap.put("orgCode", StringUtils.isEmpty(search.getOrgCode()) ? null : search.getOrgCode());
		Map<String, Object> map = new HashMap<String, Object>();
		if (StringUtils.isNotEmpty(search.getTargetNo())) {
			map.put("pointCuts", integrityMedicalService.findPointCuts(paramMap));
		} else {
			map.put("pointCuts", null);
		}
		return map;
	}

	/**
	 * 医生年度周期内已记分值
	 * @param search
	 * @return
	 * @throws BusinessException
	 */
	@RequestMapping("mediCalContentPoint.do")
	@ResponseBody
	public Map<String, Object> mediCalContentPoint(@ModelAttribute WarningDeductionVO search)
			throws BusinessException {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("idStandardscore", StringUtils.isEmpty(search.getIdStandardscore()) ? null : search.getIdStandardscore());
		paramMap.put("targetNo", StringUtils.isEmpty(search.getTargetNo()) ? null : search.getTargetNo());
		Map<String, Object> map = new HashMap<String, Object>();
		if(StringUtils.isNotEmpty(search.getTargetNo())){
			map.put("pointScose", integrityMedicalService.mediCalContentPoint(paramMap));
		}else{
			map.put("pointScose", null);
		}
		return map;
	}
	
	/**
	 * 机构对象当前细则对应的考核内容项下所有细则信息
	 * @param search
	 * @return
	 * @throws BusinessException
	 */
	@RequestMapping("findIdStandardScores.do")
	@ResponseBody
	public Map<String, Object> findIdStandardScores(@ModelAttribute WarningDeductionVO search)
			throws BusinessException {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("idStandardscore", StringUtils.isEmpty(search.getIdStandardscore()) ? null : search.getIdStandardscore());
		Map<String, Object> map = new HashMap<String, Object>();
		if(StringUtils.isNotEmpty(search.getIdStandardscore())){
			map.put("standardscores", integrityMedicalService.findIdStandardScores(paramMap));
		}else{
			map.put("standardscores", null);
		}
		return map;
	}
	
	/**
	 * 临时扣分查询(有限制条件)
	 * @param search
	 * @param request
	 * @return
	 * @throws BusinessException
	 */
	@RequestMapping("findPointCutStorageTemps.do")
	@ResponseBody
	public Map<String, Object> findPointCutStorageTemps(@ModelAttribute PointCutVO search, HttpServletRequest request)
			throws BusinessException {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("caseType", StringUtils.isEmpty(search.getCaseType()) ? null : search.getCaseType());
		paramMap.put("caseNo", StringUtils.isEmpty(search.getCaseNo()) ? null : search.getCaseNo());
		Map<String, Object> map = new HashMap<String, Object>();
		boolean isTrue = StringUtils.isNotEmpty(search.getCaseNo());
		if (isTrue) {
			map.put("pointCutStorageTemps", integrityMedicalService.findPointCutStorageTemps(paramMap));
		} else {
			map.put("pointCutStorageTemps", null);
		}
		return map;
	}
	
	/**
	 * 记分临时信息查询(包含暂存记分数据)
	 * @param search
	 * @param request
	 * @return
	 * @throws BusinessException
	 */
	@RequestMapping("findPointCutStorageCollections.do")
	@ResponseBody
	public Map<String, Object> findPointCutStorageCollections(@ModelAttribute PointCutVO search, HttpServletRequest request)
			throws BusinessException {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("caseType", StringUtils.isEmpty(search.getCaseType()) ? null : search.getCaseType());
		paramMap.put("caseNo", StringUtils.isEmpty(search.getCaseNo()) ? null : search.getCaseNo());
		paramMap.put("targetType", StringUtils.isEmpty(search.getTargetType()) ? null : search.getTargetType());
		paramMap.put("targetNo", StringUtils.isEmpty(search.getTargetNo()) ? null : search.getTargetNo());
		paramMap.put("orgCode", StringUtils.isEmpty(search.getOrgCode()) ? null : search.getOrgCode());
		Map<String, Object> map = new HashMap<String, Object>();
		if(StringUtils.isNotEmpty(search.getCaseType())
				&&StringUtils.isNotEmpty(search.getCaseNo())){
			map.put("pointCutCollections", integrityMedicalService.findPointCutStorageCollections(paramMap));
		}else{
			map.put("pointCutCollections", null);
		}
		return map;
	}
}
